import 'package:course_control/config/com_colors.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_utils/flutter_utils.dart';
import 'package:flutter_widgets/flutter_widgets.dart';
import 'package:from_css_color/from_css_color.dart';

import 'package:get/get.dart';

import '../../../../config/styles.dart';
import '../../../../gen/assets.gen.dart';
import '../../../../widgets/widgets.dart';
import '../controllers/more_controller.dart';

class MoreView extends GetView<MoreController> {
  const MoreView({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.transparent,
      body: Padding(
        padding: EdgeInsets.symmetric(horizontal: 20.ratio, vertical: 50.ratio),
        child: TransparentContain(
          width: double.infinity,
          child: Padding(
            padding: EdgeInsets.symmetric(horizontal: 30.ratio),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              mainAxisAlignment: MainAxisAlignment.spaceEvenly,
              children: [
                Text(
                  '教室环境控制',
                  style: TextStyles.titleBigStyle,
                ),
                Obx(() {
                  return SizedBox(
                    width: (243 + 30) * 3.ratio,
                    child: Wrap(
                      spacing: 30.ratio,
                      runSpacing: 30.ratio,
                      children: [
                        _builtItem(
                            Assets.images.pc.path, '教师机', controller.pc.value),
                        _builtItem(Assets.images.projector2.path, '投影机',
                            controller.projector.value),
                        _builtItem(Assets.images.power.path, '功率电源',
                            controller.power.value),
                        _builtItem(Assets.images.lamp.path, '灯光',
                            controller.lamp.value),
                        _builtItem(Assets.images.curtain.path, '窗帘',
                            controller.curtain.value),
                        _builtItem(
                            Assets.images.air.path, '空调', controller.air.value),
                      ],
                    ),
                  );
                })
              ],
            ),
          ),
        ),
      ),
    );
  }

  Widget _builtItem(String imgPath, String title, bool value) {
    return Container(
      width: 243.ratio,
      height: 174.ratio,
      decoration: BoxDecoration(
          color: Colors.white, borderRadius: BorderRadius.circular(10.ratio)),
      padding: EdgeInsets.symmetric(horizontal: 25.ratio, vertical: 17.ratio),
      child: Row(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          CommonImage.asset(
            imgPath,
            width: 40.ratio,
          ),
          const Spacer(),
          Column(
            children: [
              Text(
                title,
                style: TextStyles.titleInverseStyle,
              ),
              Text(
                value ? '开' : '关',
                style: TextStyle(fontSize: 20.ratio, color: YJColors.subBlue),
              ),
              const Spacer(),
              CupertinoSwitch(
                value: value,
                onChanged: (value) => controller.onChange(value, title),
                activeColor: YJColors.subBlue,
                trackColor: fromCssColor('#9C9C9C'),
              )
            ],
          )
        ],
      ),
    );
  }
}
